package com.example.designer.iter.impl;

import com.example.designer.iter.inte.Menu;
import com.example.designer.iter.pojo.Foot;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 数组实现的菜单类
 */
public class ArrayMenu implements Menu {

    private Integer index_max = 4;
    private Integer index = 0;
    Foot[] footArray;

    public ArrayMenu() {
        this.footArray = new Foot[index_max];
        addItem(10,"包子");
        addItem(10,"饺子");
        addItem(10,"馅饼");
        addItem(10,"粥");
    }

    public void addItem(Integer price, String name) {
        Foot foot = new Foot(price, name);
        if (index >= index_max){
            System.out.println("菜单已经满了");
        }else {
            footArray[index] = foot;
            index++;
        }
    }



    @Override
    public Iterator<Foot> createIterator() {
        return new ArrayIterator(footArray);
    }
}
